﻿namespace UnityEditor
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using UnityEditorInternal;
    using UnityEngine;

    internal class BaseProjectWindow : SearchableEditorWindow
    {
        private const float kBaseIndent = 17f;
        private const double kDropExpandTimeout = 0.7;
        private const float kFoldoutSize = 14f;
        private const float kIndent = 16f;
        private List<int> m_CurrentDragSelectionIDs = new List<int>();
        private bool m_DidSelectSearchResult;
        private DropData m_DropData;
        private static float m_DropNextToAreaHeight = 3f;
        private int m_EditNameInstanceID;
        private ProjectWindowUtil.EndAction m_EndNameEditAction;
        [SerializeField]
        private int[] m_ExpandedArray = new int[0];
        private FilteredHierarchy m_FilteredHierarchy;
        private float m_FocusTime;
        private int m_FrameAfterRelayout;
        private Rect m_NameEditRect = new Rect(0f, 0f, 1f, 1f);
        private string m_NameEditString = string.Empty;
        private bool m_NeedsRelayout;
        private string m_NewAssetExtension;
        private string m_NewAssetFolder;
        private Texture2D m_NewAssetIcon;
        private int m_NewAssetIndent;
        private string m_NewAssetName;
        private string m_NewAssetResourceFile;
        private int m_NewAssetSortInstanceID;
        private PingData m_Ping = new PingData();
        private bool m_ProjectViewInternalSelectionChange;
        private NameEditMode m_RealEditNameMode;
        private static float m_RowHeight = 16f;
        [NonSerialized]
        private Rect m_ScreenRect;
        public Vector2 m_ScrollPosition;
        public Vector2 m_ScrollPositionFiltered;
        private bool m_StillWantsNameEditing;
        private static Styles ms_Styles;
        private static Color[] s_DarkColors = new Color[] { new Color(0.705f, 0.705f, 0.705f, 1f), new Color(0.3f, 0.5f, 0.85f, 1f), new Color(0.7f, 0.4f, 0.4f, 1f), new Color(0.705f, 0.705f, 0.705f, 1f), Color.white, new Color(0.67f, 0.76f, 1f), new Color(1f, 0.71f, 0.71f, 1f), Color.white };
        private static Color[] s_HierarchyColors = new Color[] { Color.black, new Color(0f, 0.15f, 0.51f, 1f), new Color(0.25f, 0.05f, 0.05f, 1f), Color.black, Color.white, new Color(0.67f, 0.76f, 1f), new Color(1f, 0.71f, 0.71f, 1f), Color.white };

        private void Awake()
        {
            if (base.m_HierarchyType == HierarchyType.Assets)
            {
                this.m_ExpandedArray = InternalEditorUtility.expandedProjectWindowItems;
            }
        }

        private void BeginMouseEditing()
        {
            if (this.m_StillWantsNameEditing)
            {
                this.BeginNameEditing(Selection.activeInstanceID);
            }
            base.Repaint();
        }

        private void BeginNameEditing(int instanceID)
        {
            if (this.NamingAsset())
            {
                this.EndNameEditing();
            }
            if (base.hasSearchFilter)
            {
                this.m_EditNameMode = NameEditMode.None;
            }
            else
            {
                IHierarchyProperty property = new HierarchyProperty(base.m_HierarchyType);
                property.Find(instanceID, null);
                if (property.isValid)
                {
                    this.m_EditNameMode = NameEditMode.Renaming;
                    this.m_EditNameInstanceID = instanceID;
                    EditorGUI.s_RecycledEditor.content.text = property.name;
                    EditorGUI.s_RecycledEditor.SelectAll();
                }
                else
                {
                    this.m_EditNameMode = NameEditMode.None;
                }
            }
        }

        internal void BeginPreimportedNameEditing(int instanceID, ProjectWindowUtil.EndAction endAction, string pathName, Texture2D icon, string resourceFile)
        {
            if (this.NamingAsset())
            {
                this.EndNameEditing();
            }
            this.m_EndNameEditAction = endAction;
            if (!pathName.StartsWith("assets/", StringComparison.CurrentCultureIgnoreCase))
            {
                pathName = AssetDatabase.GetUniquePathNameAtSelectedPath(pathName);
            }
            else
            {
                pathName = AssetDatabase.GenerateUniqueAssetPath(pathName);
            }
            this.m_NewAssetFolder = Path.GetDirectoryName(pathName);
            this.m_NewAssetIcon = icon;
            this.m_NewAssetName = Path.GetFileNameWithoutExtension(pathName);
            this.m_NewAssetExtension = Path.GetExtension(pathName);
            this.m_NewAssetIndent = 0;
            this.m_NewAssetSortInstanceID = 0;
            this.m_NewAssetResourceFile = resourceFile;
            Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID);
            if (base.hasSearchFilter)
            {
                base.m_SearchFilter = string.Empty;
                base.m_SearchMode = SearchableEditorWindow.SearchMode.All;
            }
            int targetInstanceID = AssetDatabase.LoadAssetAtPath(this.m_NewAssetFolder, typeof(UnityEngine.Object)).GetInstanceID();
            this.RevealObject(targetInstanceID);
            this.SetExpanded(targetInstanceID, true);
            IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
            newHierarchyProperty.Reset();
            float yPos = 0f;
            if (!this.m_NewAssetFolder.Equals("assets", StringComparison.CurrentCultureIgnoreCase))
            {
                while (newHierarchyProperty.Next(this.m_ExpandedArray))
                {
                    string assetPath = AssetDatabase.GetAssetPath(newHierarchyProperty.instanceID);
                    yPos += m_RowHeight;
                    if (string.Equals(assetPath, this.m_NewAssetFolder, StringComparison.CurrentCultureIgnoreCase))
                    {
                        yPos = this.FindPositionInsideDir(newHierarchyProperty, yPos);
                        break;
                    }
                }
            }
            else
            {
                yPos = this.FindPositionInsideDir(newHierarchyProperty, yPos);
            }
            float left = (17f + (16f * this.m_NewAssetIndent)) + this.IconWidth;
            this.m_NameEditRect = new Rect(left, yPos, 100f, m_RowHeight);
            float max = yPos;
            float min = ((max - base.position.height) + 20f) + m_RowHeight;
            this.m_ScrollPosition.y = Mathf.Clamp(this.m_ScrollPosition.y, min, max);
            this.m_EditNameMode = NameEditMode.PreImportNaming;
            this.m_EditNameInstanceID = instanceID;
            EditorGUI.s_RecycledEditor.content.text = this.m_NameEditString = this.m_NewAssetName;
            EditorGUI.s_RecycledEditor.SelectAll();
        }

        private void CancelNameEditing()
        {
            this.m_EditNameMode = NameEditMode.None;
            this.m_EndNameEditAction = ProjectWindowUtil.EndAction.None;
        }

        internal override void ClickedSearchField()
        {
            this.EndNameEditing();
        }

        private int ControlIDForProperty(IHierarchyProperty property)
        {
            if (property != null)
            {
                return (property.instanceID + 0x989680);
            }
            return -1;
        }

        private void CopyGO()
        {
            Unsupported.CopyGameObjectsToPasteboard();
        }

        private void CreateAssetPopup()
        {
            GUIContent content = new GUIContent("Create");
            Rect position = GUILayoutUtility.GetRect(content, EditorStyles.toolbarDropDown, null);
            GUI.Label(position, content, EditorStyles.toolbarDropDown);
            if ((Event.current.type == EventType.MouseDown) && position.Contains(Event.current.mousePosition))
            {
                GUIUtility.hotControl = 0;
                ProjectWindowUtil.s_PreferredProjectWindow = this as ProjectWindow;
                EditorUtility.DisplayPopupMenu(position, "Assets/Create", null);
                Event.current.Use();
            }
        }

        private void CreateGameObjectPopup()
        {
            GUIContent content = new GUIContent("Create");
            Rect position = GUILayoutUtility.GetRect(content, EditorStyles.toolbarDropDown, null);
            GUI.Label(position, content, EditorStyles.toolbarDropDown);
            if ((Event.current.type == EventType.MouseDown) && position.Contains(Event.current.mousePosition))
            {
                GUIUtility.hotControl = 0;
                EditorUtility.DisplayPopupMenu(position, "GameObject/Create Other", null);
                Event.current.Use();
            }
        }

        private void DeleteGO()
        {
            Unsupported.DeleteGameObjectSelection();
        }

        internal static void DeleteSelectedAssets(bool askIfSure)
        {
            string[] mainSelectedPaths = GetMainSelectedPaths();
            if (mainSelectedPaths.Length != 0)
            {
                if (askIfSure)
                {
                    string str = "Delete selected asset";
                    if (mainSelectedPaths.Length > 1)
                    {
                        str = str + "s";
                    }
                    if (!EditorUtility.DisplayDialog(str + "?", "You cannot undo this action.", "Delete", "Cancel"))
                    {
                        return;
                    }
                }
                AssetDatabase.StartAssetEditing();
                foreach (string str2 in mainSelectedPaths)
                {
                    AssetDatabase.MoveAssetToTrash(str2);
                }
                AssetDatabase.StopAssetEditing();
            }
        }

        private DragAndDropVisualMode DoDrag(IHierarchyProperty property, bool perform)
        {
            HierarchyProperty property2 = new HierarchyProperty(base.m_HierarchyType);
            if ((property == null) || !property2.Find(property.instanceID, null))
            {
                property2 = null;
            }
            if (base.m_HierarchyType == HierarchyType.Assets)
            {
                return InternalEditorUtility.ProjectWindowDrag(property2, perform);
            }
            return InternalEditorUtility.HierarchyWindowDrag(property2, perform);
        }

        private void DragCleanup(bool revertExpanded)
        {
            if (this.m_DropData != null)
            {
                if ((this.m_DropData.expandedArrayBeforeDrag != null) && revertExpanded)
                {
                    this.m_ExpandedArray = this.m_DropData.expandedArrayBeforeDrag;
                }
                this.m_DropData = null;
                base.Repaint();
            }
        }

        private void DragElement(IHierarchyProperty property, bool dropOnTopOfElement)
        {
            if (Event.current.type == EventType.DragPerform)
            {
                IHierarchyProperty parentProperty = property;
                DragAndDropVisualMode none = DragAndDropVisualMode.None;
                if (dropOnTopOfElement)
                {
                    none = this.DoDrag(parentProperty, true);
                }
                if ((none == DragAndDropVisualMode.None) && (property != null))
                {
                    parentProperty = this.GetParentProperty(parentProperty);
                    none = this.DoDrag(parentProperty, true);
                }
                if (none != DragAndDropVisualMode.None)
                {
                    DragAndDrop.AcceptDrag();
                    this.DragCleanup(false);
                    ArrayList list = new ArrayList();
                    foreach (UnityEngine.Object obj2 in DragAndDrop.objectReferences)
                    {
                        IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
                        if (newHierarchyProperty.Find(obj2.GetInstanceID(), null))
                        {
                            IHierarchyProperty property4 = this.GetParentProperty(newHierarchyProperty);
                            if ((property4 != null) && ((parentProperty == null) || (property4.pptrValue == parentProperty.pptrValue)))
                            {
                                list.Add(obj2);
                            }
                        }
                    }
                    if (list.Count > 0)
                    {
                        Selection.objects = (UnityEngine.Object[]) list.ToArray(typeof(UnityEngine.Object));
                        this.RevealObjects(Selection.instanceIDs);
                        this.FrameObject(Selection.activeInstanceID);
                    }
                    GUIUtility.ExitGUI();
                }
                else
                {
                    this.DragCleanup(true);
                }
            }
            else
            {
                if (this.m_DropData == null)
                {
                    this.m_DropData = new DropData();
                }
                this.m_DropData.dropOnControlID = 0;
                this.m_DropData.dropPreviousControlID = 0;
                int num2 = this.ControlIDForProperty(property);
                if (num2 != this.m_DropData.lastControlID)
                {
                    this.m_DropData.lastControlID = this.ControlIDForProperty(property);
                    this.m_DropData.expandItemBeginTimer = Time.realtimeSinceStartup;
                }
                bool flag = (Time.realtimeSinceStartup - this.m_DropData.expandItemBeginTimer) > 0.7;
                if (((property != null) && property.hasChildren) && (flag && !property.IsExpanded(this.m_ExpandedArray)))
                {
                    if (this.m_DropData.expandedArrayBeforeDrag == null)
                    {
                        this.m_DropData.expandedArrayBeforeDrag = this.m_ExpandedArray;
                    }
                    this.SetExpanded(property.instanceID, true);
                }
                DragAndDropVisualMode mode2 = DragAndDropVisualMode.None;
                if (dropOnTopOfElement)
                {
                    mode2 = this.DoDrag(property, false);
                }
                if (mode2 != DragAndDropVisualMode.None)
                {
                    this.m_DropData.dropOnControlID = num2;
                    DragAndDrop.visualMode = mode2;
                }
                else if ((property != null) && (base.m_SearchFilter == string.Empty))
                {
                    IHierarchyProperty property5 = this.GetParentProperty(property);
                    mode2 = this.DoDrag(property5, false);
                    if (mode2 != DragAndDropVisualMode.None)
                    {
                        this.m_DropData.dropPreviousControlID = num2;
                        this.m_DropData.dropOnControlID = this.ControlIDForProperty(property5);
                        DragAndDrop.visualMode = mode2;
                    }
                }
                base.Repaint();
            }
            Event.current.Use();
        }

        private void DrawPreImportedIcon(float offset)
        {
            if ((Event.current.type == EventType.Repaint) && (this.m_NewAssetIcon != null))
            {
                ms_Styles.label.padding.left = 0;
                ms_Styles.label.Draw(new Rect((this.m_NewAssetIndent * 0x10) + 17f, offset - 16f, 16f, 16f), EditorGUIUtility.TempContent(this.m_NewAssetIcon), 0);
            }
        }

        private void DuplicateGO()
        {
            Unsupported.DuplicateGameObjectsUsingPasteboard();
        }

        internal static void DuplicateSelectedAssets()
        {
            AssetDatabase.Refresh();
            UnityEngine.Object[] objects = Selection.objects;
            bool flag = true;
            foreach (UnityEngine.Object obj2 in objects)
            {
                AnimationClip clip = obj2 as AnimationClip;
                if (((clip == null) || ((clip.hideFlags & HideFlags.NotEditable) == 0)) || !AssetDatabase.Contains(clip))
                {
                    flag = false;
                }
            }
            ArrayList list = new ArrayList();
            bool flag2 = false;
            if (flag)
            {
                foreach (UnityEngine.Object obj3 in objects)
                {
                    AnimationClip source = obj3 as AnimationClip;
                    if ((source != null) && ((source.hideFlags & HideFlags.NotEditable) != 0))
                    {
                        string path = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(Path.GetDirectoryName(AssetDatabase.GetAssetPath(obj3)), source.name) + ".anim");
                        AnimationClip dest = new AnimationClip();
                        EditorUtility.CopySerialized(source, dest);
                        AssetDatabase.CreateAsset(dest, path);
                        list.Add(path);
                    }
                }
            }
            else
            {
                foreach (UnityEngine.Object obj4 in Selection.GetFiltered(typeof(UnityEngine.Object), UnityEditor.SelectionMode.Assets))
                {
                    string assetPath = AssetDatabase.GetAssetPath(obj4);
                    string newPath = AssetDatabase.GenerateUniqueAssetPath(assetPath);
                    if (newPath.Length != 0)
                    {
                        flag2 |= !AssetDatabase.CopyAsset(assetPath, newPath);
                    }
                    else
                    {
                        flag2 |= true;
                    }
                    if (!flag2)
                    {
                        list.Add(newPath);
                    }
                }
            }
            AssetDatabase.Refresh();
            UnityEngine.Object[] objArray6 = new UnityEngine.Object[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                objArray6[i] = AssetDatabase.LoadMainAssetAtPath(list[i] as string);
            }
            Selection.objects = objArray6;
        }

        private void EditName()
        {
            if (this.NamingAsset())
            {
                Event current = Event.current;
                if (current.type == EventType.KeyDown)
                {
                    if (current.keyCode == KeyCode.Escape)
                    {
                        current.Use();
                        this.CancelNameEditing();
                    }
                    if ((current.keyCode == KeyCode.Return) || (current.keyCode == KeyCode.KeypadEnter))
                    {
                        current.Use();
                        this.EndNameEditing();
                        GUIUtility.ExitGUI();
                    }
                }
                GUI.changed = false;
                GUIUtility.GetControlID(0x40c0870, FocusType.Passive);
                GUI.SetNextControlName("ProjectWindowRenameField");
                GUI.FocusControl("ProjectWindowRenameField");
                GUIStyle textField = EditorStyles.textField;
                EditorStyles.s_Current.m_TextField = "PR TextField";
                this.m_NameEditRect.xMax = GUIClip.visibleRect.width;
                Rect nameEditRect = this.m_NameEditRect;
                this.m_NameEditString = EditorGUI.TextField(nameEditRect, this.m_NameEditString);
                EditorStyles.s_Current.m_TextField = textField;
                if (current.type == EventType.ScrollWheel)
                {
                    current.Use();
                }
            }
        }

        private void EndNameEditing()
        {
            NameEditMode editNameMode = this.m_EditNameMode;
            if (editNameMode != NameEditMode.Renaming)
            {
                if (editNameMode != NameEditMode.PreImportNaming)
                {
                    return;
                }
            }
            else
            {
                this.m_EditNameMode = NameEditMode.None;
                ObjectNames.SetNameSmartWithInstanceID(this.m_EditNameInstanceID, this.m_NameEditString);
                return;
            }
            this.m_EditNameMode = NameEditMode.None;
            if (this.m_NameEditString == string.Empty)
            {
                this.m_NameEditString = this.m_NewAssetName;
            }
            ProjectWindowUtil.EndNameEditAction(this.m_EndNameEditAction, this.m_EditNameInstanceID, this.m_NewAssetFolder + "/" + this.m_NameEditString + this.m_NewAssetExtension, this.m_NewAssetResourceFile);
            this.m_EndNameEditAction = ProjectWindowUtil.EndAction.None;
        }

        private void ExecuteCommandGUI()
        {
            if (base.m_HierarchyType == HierarchyType.Assets)
            {
                this.ExecuteCommandGUIProject();
            }
            else
            {
                this.ExecuteCommandGUIHierarchy();
            }
            if (Event.current.commandName == "FrameSelected")
            {
                if (Event.current.type == EventType.ExecuteCommand)
                {
                    this.FrameObject(Selection.activeInstanceID);
                }
                Event.current.Use();
                GUIUtility.ExitGUI();
            }
            else if (Event.current.commandName == "Find")
            {
                if (Event.current.type == EventType.ExecuteCommand)
                {
                    base.FocusSearchField();
                }
                Event.current.Use();
            }
        }

        private void ExecuteCommandGUIHierarchy()
        {
            bool flag = Event.current.type == EventType.ExecuteCommand;
            if ((Event.current.commandName == "Delete") || (Event.current.commandName == "SoftDelete"))
            {
                if (flag)
                {
                    Unsupported.DeleteGameObjectSelection();
                }
                Event.current.Use();
                GUIUtility.ExitGUI();
            }
            else if (Event.current.commandName == "Duplicate")
            {
                if (flag)
                {
                    Unsupported.DuplicateGameObjectsUsingPasteboard();
                }
                Event.current.Use();
                GUIUtility.ExitGUI();
            }
            else if (Event.current.commandName == "Copy")
            {
                if (flag)
                {
                    Unsupported.CopyGameObjectsToPasteboard();
                }
                Event.current.Use();
                GUIUtility.ExitGUI();
            }
            else if (Event.current.commandName == "Paste")
            {
                if (flag)
                {
                    Unsupported.PasteGameObjectsFromPasteboard();
                }
                Event.current.Use();
                GUIUtility.ExitGUI();
            }
            else if (Event.current.commandName == "SelectAll")
            {
                if (flag)
                {
                    this.SelectAll();
                }
                Event.current.Use();
                GUIUtility.ExitGUI();
            }
        }

        private void ExecuteCommandGUIProject()
        {
            bool flag = Event.current.type == EventType.ExecuteCommand;
            if ((Event.current.commandName == "Delete") || (Event.current.commandName == "SoftDelete"))
            {
                Event.current.Use();
                if (flag)
                {
                    bool askIfSure = Event.current.commandName == "SoftDelete";
                    DeleteSelectedAssets(askIfSure);
                }
                GUIUtility.ExitGUI();
            }
            else if (Event.current.commandName == "Duplicate")
            {
                if (flag)
                {
                    Event.current.Use();
                    DuplicateSelectedAssets();
                    GUIUtility.ExitGUI();
                }
                else if (Selection.GetFiltered(typeof(UnityEngine.Object), UnityEditor.SelectionMode.Assets).Length != 0)
                {
                    Event.current.Use();
                }
            }
            else if (Event.current.commandName == "FocusProjectWindow")
            {
                if (Event.current.type == EventType.ExecuteCommand)
                {
                    this.FrameObject(Selection.activeInstanceID);
                    Event.current.Use();
                    base.Focus();
                    GUIUtility.ExitGUI();
                }
                else
                {
                    Event.current.Use();
                }
            }
            else if (Event.current.commandName == "SelectAll")
            {
                if (Event.current.type == EventType.ExecuteCommand)
                {
                    this.SelectAll();
                }
                Event.current.Use();
            }
        }

        private float FindPositionInsideDir(IHierarchyProperty property, float yPos)
        {
            this.m_NewAssetIndent = property.depth + 1;
            string str = this.m_NewAssetFolder + "/";
            while (property.Next(this.m_ExpandedArray))
            {
                string assetPath = AssetDatabase.GetAssetPath(property.instanceID);
                string str3 = assetPath + "/";
                if ((str3.Length >= str.Length) && str3.Substring(0, str.Length).Equals(str, StringComparison.CurrentCultureIgnoreCase))
                {
                    if (this.m_NewAssetFolder.Equals(Path.GetDirectoryName(assetPath), StringComparison.CurrentCultureIgnoreCase) && (EditorUtility.SemiNumericCompare(Path.GetFileNameWithoutExtension(assetPath), this.m_NewAssetName) > 0))
                    {
                        this.m_NewAssetIndent = property.depth;
                        this.m_NewAssetSortInstanceID = property.instanceID;
                        return yPos;
                    }
                }
                else
                {
                    this.m_NewAssetSortInstanceID = property.instanceID;
                    return yPos;
                }
                yPos += m_RowHeight;
            }
            return yPos;
        }

        internal bool FrameObject(int targetInstanceID)
        {
            return this.FrameObject(targetInstanceID, true);
        }

        internal bool FrameObject(int targetInstanceID, bool allowClearSearchFilter)
        {
            IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
            if (this.m_NeedsRelayout)
            {
                this.m_FrameAfterRelayout = targetInstanceID;
                return newHierarchyProperty.Find(targetInstanceID, this.m_ExpandedArray);
            }
            this.RevealObject(targetInstanceID, allowClearSearchFilter);
            newHierarchyProperty = this.GetNewHierarchyProperty();
            if (!newHierarchyProperty.Find(targetInstanceID, this.m_ExpandedArray))
            {
                return false;
            }
            int row = newHierarchyProperty.row;
            float max = m_RowHeight * row;
            float min = (max - this.m_ScreenRect.height) + m_RowHeight;
            if (!base.hasSearchFilter)
            {
                this.m_ScrollPosition.y = Mathf.Clamp(this.m_ScrollPosition.y, min, max);
            }
            else
            {
                this.m_ScrollPositionFiltered.y = Mathf.Clamp(this.m_ScrollPositionFiltered.y, min, max);
            }
            base.Repaint();
            return true;
        }

        private IHierarchyProperty GetActiveSelected()
        {
            return this.GetFirstSelected();
        }

        private UnityEngine.Object[] GetDragAndDropObjects(UnityEngine.Object dragged)
        {
            ArrayList list = new ArrayList();
            list.AddRange(this.GetSelectedReferences());
            if (list.Contains(dragged))
            {
                return (list.ToArray(typeof(UnityEngine.Object)) as UnityEngine.Object[]);
            }
            return new UnityEngine.Object[] { dragged };
        }

        private string[] GetDragAndDropPaths(int dragged)
        {
            string assetPath = AssetDatabase.GetAssetPath(dragged);
            if (base.m_HierarchyType != HierarchyType.Assets)
            {
                return new string[0];
            }
            ArrayList list = new ArrayList();
            list.AddRange(GetMainSelectedPaths());
            if (list.Contains(assetPath))
            {
                return (list.ToArray(typeof(string)) as string[]);
            }
            return new string[] { assetPath };
        }

        private IHierarchyProperty GetFirst()
        {
            IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
            if (newHierarchyProperty.Next(this.m_ExpandedArray))
            {
                return newHierarchyProperty;
            }
            return null;
        }

        private IHierarchyProperty GetFirstSelected()
        {
            int row = 0x3b9aca00;
            IHierarchyProperty property = null;
            foreach (int num2 in Selection.instanceIDs)
            {
                IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
                if (newHierarchyProperty.Find(num2, this.m_ExpandedArray) && (newHierarchyProperty.row < row))
                {
                    row = newHierarchyProperty.row;
                    property = newHierarchyProperty;
                }
            }
            return property;
        }

        private IHierarchyProperty GetLast()
        {
            IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
            int count = newHierarchyProperty.CountRemaining(this.m_ExpandedArray);
            if (count != 0)
            {
                newHierarchyProperty.Reset();
                if (newHierarchyProperty.Skip(count, this.m_ExpandedArray))
                {
                    return newHierarchyProperty;
                }
            }
            return null;
        }

        private IHierarchyProperty GetLastSelected()
        {
            int row = -1;
            IHierarchyProperty property = null;
            foreach (int num2 in Selection.instanceIDs)
            {
                IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
                if (newHierarchyProperty.Find(num2, this.m_ExpandedArray) && (newHierarchyProperty.row > row))
                {
                    row = newHierarchyProperty.row;
                    property = newHierarchyProperty;
                }
            }
            return property;
        }

        private static string[] GetMainSelectedPaths()
        {
            ArrayList list = new ArrayList();
            foreach (int num in Selection.instanceIDs)
            {
                if (AssetDatabase.IsMainAsset(num))
                {
                    string assetPath = AssetDatabase.GetAssetPath(num);
                    list.Add(assetPath);
                }
            }
            return (list.ToArray(typeof(string)) as string[]);
        }

        public IHierarchyProperty GetNewHierarchyProperty()
        {
            if (this.m_FilteredHierarchy == null)
            {
                this.m_FilteredHierarchy = new FilteredHierarchy(base.m_HierarchyType);
                this.m_FilteredHierarchy.searchFilter = SearchableEditorWindow.CreateFilter(base.m_SearchFilter, base.m_SearchMode);
            }
            return FilteredHierarchyProperty.CreateHierarchyPropertyForFilter(this.m_FilteredHierarchy);
        }

        private IHierarchyProperty GetParentProperty(IHierarchyProperty property)
        {
            IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
            if (newHierarchyProperty.Find(property.instanceID, this.m_ExpandedArray) && newHierarchyProperty.Parent())
            {
                int instanceID = newHierarchyProperty.instanceID;
                newHierarchyProperty.Reset();
                if (newHierarchyProperty.Find(instanceID, this.m_ExpandedArray))
                {
                    return newHierarchyProperty;
                }
            }
            return null;
        }

        private UnityEngine.Object[] GetSelectedReferences()
        {
            ArrayList list = new ArrayList();
            foreach (UnityEngine.Object obj2 in Selection.objects)
            {
                if (AssetDatabase.Contains(obj2) != (base.m_HierarchyType == HierarchyType.GameObjects))
                {
                    list.Add(obj2);
                }
            }
            return (list.ToArray(typeof(UnityEngine.Object)) as UnityEngine.Object[]);
        }

        private List<int> GetSelection(IHierarchyProperty property, bool mouseDown)
        {
            List<int> list = new List<int>();
            if (EditorGUI.actionKey)
            {
                list.AddRange(Selection.instanceIDs);
                if (list.Contains(property.instanceID))
                {
                    list.Remove(property.instanceID);
                    return list;
                }
                list.Add(property.instanceID);
                return list;
            }
            if (Event.current.shift)
            {
                IHierarchyProperty property4;
                IHierarchyProperty property5;
                IHierarchyProperty firstSelected = this.GetFirstSelected();
                IHierarchyProperty lastSelected = this.GetLastSelected();
                if ((firstSelected == null) || !firstSelected.isValid)
                {
                    list.Add(property.instanceID);
                    return list;
                }
                if (property.row > lastSelected.row)
                {
                    property4 = firstSelected;
                    property5 = property;
                }
                else
                {
                    property4 = property;
                    property5 = lastSelected;
                }
                list.Add(property4.instanceID);
                while (property4.Next(this.m_ExpandedArray))
                {
                    list.Add(property4.instanceID);
                    if (property4.instanceID == property5.instanceID)
                    {
                        return list;
                    }
                }
                return list;
            }
            if (mouseDown)
            {
                list.AddRange(Selection.instanceIDs);
                if (list.Contains(property.instanceID))
                {
                    return list;
                }
                list.Clear();
            }
            list.Add(property.instanceID);
            return list;
        }

        private void HandlePing()
        {
            this.m_Ping.HandlePing();
            if (this.m_Ping.isPinging)
            {
                base.Repaint();
            }
        }

        private void HierarchyView()
        {
            int num5;
            if ((Event.current.type == EventType.MouseDown) || (Event.current.type == EventType.KeyDown))
            {
                this.m_StillWantsNameEditing = false;
            }
            bool hasFocus = base.m_Parent.hasFocus;
            Hashtable hashtable = new Hashtable();
            foreach (int num in Selection.instanceIDs)
            {
                hashtable.Add(num, null);
            }
            IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
            float top = 0f;
            int num4 = 0;
            num4 = newHierarchyProperty.CountRemaining(this.m_ExpandedArray);
            newHierarchyProperty.Reset();
            Rect viewRect = new Rect(0f, 0f, 1f, num4 * m_RowHeight);
            if (this.m_EditNameMode == NameEditMode.PreImportNaming)
            {
                viewRect.height += m_RowHeight;
            }
            if (base.hasSearchFilter)
            {
                this.m_ScrollPositionFiltered = GUI.BeginScrollView(this.m_ScreenRect, this.m_ScrollPositionFiltered, viewRect);
                num5 = Mathf.RoundToInt(this.m_ScrollPositionFiltered.y) / Mathf.RoundToInt(m_RowHeight);
            }
            else
            {
                this.m_ScrollPosition = GUI.BeginScrollView(this.m_ScreenRect, this.m_ScrollPosition, viewRect);
                num5 = Mathf.RoundToInt(this.m_ScrollPosition.y) / Mathf.RoundToInt(m_RowHeight);
            }
            this.EditName();
            if ((Event.current.type == EventType.ExecuteCommand) || (Event.current.type == EventType.ValidateCommand))
            {
                this.ExecuteCommandGUI();
                if (Event.current.type == EventType.ValidateCommand)
                {
                    GUI.EndScrollView();
                    return;
                }
            }
            this.KeyboardGUI();
            if (Event.current.type == EventType.Layout)
            {
                GUI.EndScrollView();
            }
            else
            {
                int num6 = this.ControlIDForProperty(null);
                bool flag2 = false;
                top = num5 * m_RowHeight;
                float num7 = (this.m_ScreenRect.height + top) + 16f;
                newHierarchyProperty.Skip(num5, this.m_ExpandedArray);
                bool flag3 = false;
                Rect position = new Rect(0f, 0f, 0f, 0f);
                Vector2 mousePosition = Event.current.mousePosition;
                GUIContent content = new GUIContent();
                Event current = Event.current;
                int activeInstanceID = Selection.activeInstanceID;
                if (!this.NamingAsset())
                {
                    this.m_EditNameMode = NameEditMode.None;
                }
                GUIStyle style = (base.m_HierarchyType != HierarchyType.Assets) ? ms_Styles.hiLabel : ms_Styles.label;
                Color[] colorArray = (EditorGUIUtility.skinIndex != 1) ? s_HierarchyColors : s_DarkColors;
                while (newHierarchyProperty.Next(this.m_ExpandedArray) && (top <= num7))
                {
                    Rect rect3 = new Rect(0f, top, GUIClip.visibleRect.width, m_RowHeight);
                    if (((this.m_EditNameMode == NameEditMode.PreImportNaming) && !flag2) && (newHierarchyProperty.instanceID == this.m_NewAssetSortInstanceID))
                    {
                        flag2 = true;
                        top += m_RowHeight;
                        rect3 = new Rect(0f, top, GUIClip.visibleRect.width, m_RowHeight);
                        this.DrawPreImportedIcon(top);
                    }
                    int instanceID = newHierarchyProperty.instanceID;
                    int controlID = this.ControlIDForProperty(newHierarchyProperty);
                    float num11 = 17f + (16f * newHierarchyProperty.depth);
                    if (((current.type == EventType.MouseUp) || (current.type == EventType.KeyDown)) && ((activeInstanceID == instanceID) && (Selection.instanceIDs.Length == 1)))
                    {
                        this.m_NameEditString = newHierarchyProperty.name;
                        this.m_NameEditRect = new Rect((rect3.x + num11) + this.IconWidth, rect3.y, rect3.width - num11, rect3.height);
                        this.m_EditNameInstanceID = instanceID;
                        if ((this.m_EditNameMode == NameEditMode.None) && newHierarchyProperty.isMainRepresentation)
                        {
                            this.m_EditNameMode = NameEditMode.Found;
                        }
                    }
                    if ((this.m_EditNameMode == NameEditMode.Renaming) && (this.m_EditNameInstanceID == instanceID))
                    {
                        this.m_NameEditRect = new Rect((rect3.x + num11) + this.IconWidth, rect3.y, rect3.width - num11, rect3.height);
                    }
                    if ((current.type == EventType.ContextClick) && rect3.Contains(current.mousePosition))
                    {
                        this.m_NameEditRect = new Rect((rect3.x + num11) + this.IconWidth, rect3.y, rect3.width - num11, rect3.height);
                        this.m_EditNameInstanceID = instanceID;
                        this.m_NameEditString = newHierarchyProperty.name;
                        if ((this.m_EditNameMode == NameEditMode.None) && newHierarchyProperty.isMainRepresentation)
                        {
                            this.m_EditNameMode = NameEditMode.Found;
                        }
                    }
                    if (Event.current.type == EventType.Repaint)
                    {
                        if (base.m_HierarchyType == HierarchyType.GameObjects)
                        {
                            int colorCode = newHierarchyProperty.colorCode;
                            Color color = colorArray[colorCode & 3];
                            Color color2 = colorArray[(colorCode & 3) + 4];
                            if (colorCode >= 4)
                            {
                                color.a = color2.a = 0.6f;
                            }
                            else
                            {
                                color.a = color2.a = 1f;
                            }
                            style.normal.textColor = color;
                            style.focused.textColor = color;
                            style.hover.textColor = color;
                            style.active.textColor = color;
                            style.onNormal.textColor = color2;
                            style.onHover.textColor = color2;
                            style.onActive.textColor = color2;
                            style.onFocused.textColor = color2;
                        }
                        bool flag4 = (this.m_DropData != null) && (this.m_DropData.dropPreviousControlID == controlID);
                        bool isHover = (this.m_DropData != null) && (this.m_DropData.dropOnControlID == controlID);
                        content.text = newHierarchyProperty.name;
                        content.image = newHierarchyProperty.icon;
                        style.padding.left = (int) num11;
                        bool flag6 = this.m_CurrentDragSelectionIDs.Contains(instanceID);
                        bool on = (((this.m_CurrentDragSelectionIDs.Count == 0) && hashtable.Contains(instanceID)) || flag6) || (((flag6 && (current.control || current.shift)) && hashtable.Contains(instanceID)) || ((flag6 && hashtable.Contains(instanceID)) && hashtable.Contains(this.m_CurrentDragSelectionIDs)));
                        if ((this.m_EditNameMode == NameEditMode.Renaming) && (instanceID == this.m_EditNameInstanceID))
                        {
                            content.text = string.Empty;
                            on = false;
                        }
                        style.Draw(rect3, content, isHover, isHover, on, hasFocus);
                        if (flag4)
                        {
                            flag3 = true;
                            position = new Rect(rect3.x + num11, rect3.y - m_RowHeight, rect3.width - num11, rect3.height);
                        }
                    }
                    Rect drawRect = rect3;
                    drawRect.x += num11;
                    drawRect.width -= num11;
                    if (base.m_HierarchyType == HierarchyType.Assets)
                    {
                        VCProjectHooks.OnProjectWindowItem(newHierarchyProperty.guid, drawRect);
                        if (EditorApplication.projectWindowItemOnGUI != null)
                        {
                            EditorApplication.projectWindowItemOnGUI(newHierarchyProperty.guid, drawRect);
                        }
                    }
                    if ((base.m_HierarchyType == HierarchyType.GameObjects) && (EditorApplication.hierarchyWindowItemOnGUI != null))
                    {
                        EditorApplication.hierarchyWindowItemOnGUI(newHierarchyProperty.instanceID, drawRect);
                    }
                    if (newHierarchyProperty.hasChildren && !base.hasSearchFilter)
                    {
                        bool flag8 = newHierarchyProperty.IsExpanded(this.m_ExpandedArray);
                        GUI.changed = false;
                        Rect rect5 = new Rect((17f + (16f * newHierarchyProperty.depth)) - 14f, top, 14f, m_RowHeight);
                        flag8 = GUI.Toggle(rect5, flag8, GUIContent.none, ms_Styles.foldout);
                        if (GUI.changed)
                        {
                            this.EndNameEditing();
                            if (Event.current.alt)
                            {
                                this.SetExpandedRecurse(instanceID, flag8);
                            }
                            else
                            {
                                this.SetExpanded(instanceID, flag8);
                            }
                        }
                    }
                    if (((current.type == EventType.MouseDown) && (Event.current.button == 0)) && rect3.Contains(Event.current.mousePosition))
                    {
                        if (Event.current.clickCount == 2)
                        {
                            AssetDatabase.OpenAsset(instanceID);
                            if ((base.m_HierarchyType != HierarchyType.Assets) && (SceneView.lastActiveSceneView != null))
                            {
                                SceneView.lastActiveSceneView.FrameSelected();
                            }
                            GUIUtility.ExitGUI();
                        }
                        else
                        {
                            this.EndNameEditing();
                            this.m_CurrentDragSelectionIDs = this.GetSelection(newHierarchyProperty, true);
                            GUIUtility.hotControl = controlID;
                            GUIUtility.keyboardControl = 0;
                            DragAndDropDelay stateObject = (DragAndDropDelay) GUIUtility.GetStateObject(typeof(DragAndDropDelay), controlID);
                            stateObject.mouseDownPosition = Event.current.mousePosition;
                        }
                        current.Use();
                    }
                    else if ((current.type == EventType.MouseDrag) && (GUIUtility.hotControl == controlID))
                    {
                        DragAndDropDelay delay2 = (DragAndDropDelay) GUIUtility.GetStateObject(typeof(DragAndDropDelay), controlID);
                        if (delay2.CanStartDrag())
                        {
                            this.StartDrag(newHierarchyProperty);
                            GUIUtility.hotControl = 0;
                        }
                        current.Use();
                    }
                    else if ((current.type == EventType.MouseUp) && (GUIUtility.hotControl == controlID))
                    {
                        if (rect3.Contains(current.mousePosition))
                        {
                            if ((newHierarchyProperty.isMainRepresentation && (Selection.activeInstanceID == newHierarchyProperty.instanceID)) && (((Time.realtimeSinceStartup - this.m_FocusTime) > 0.5f) && !EditorGUIUtility.HasHolddownKeyModifiers(current)))
                            {
                                this.m_StillWantsNameEditing = true;
                                EditorApplication.CallDelayed(new EditorApplication.CallbackFunction(this.BeginMouseEditing), 0.5f);
                            }
                            else
                            {
                                this.SelectionClick(newHierarchyProperty);
                            }
                            GUIUtility.hotControl = 0;
                        }
                        this.m_CurrentDragSelectionIDs.Clear();
                        current.Use();
                    }
                    else if ((current.type == EventType.ContextClick) && rect3.Contains(current.mousePosition))
                    {
                        if (base.m_HierarchyType == HierarchyType.Assets)
                        {
                            this.SelectionClickContextMenu(newHierarchyProperty);
                            ProjectWindowUtil.s_PreferredProjectWindow = this as ProjectWindow;
                            EditorUtility.DisplayPopupMenu(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f), "Assets/", null);
                            current.Use();
                        }
                        else
                        {
                            this.SelectionClickContextMenu(newHierarchyProperty);
                            GenericMenu menu = new GenericMenu();
                            menu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupCopy"), false, new GenericMenu.MenuFunction(this.CopyGO));
                            menu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupPaste"), false, new GenericMenu.MenuFunction(this.PasteGO));
                            menu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupDuplicate"), false, new GenericMenu.MenuFunction(this.DuplicateGO));
                            menu.AddSeparator(string.Empty);
                            if ((this.m_EditNameMode == NameEditMode.Found) && !base.hasSearchFilter)
                            {
                                menu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupRename"), false, new GenericMenu.MenuFunction2(this.RenameGO), newHierarchyProperty.pptrValue);
                            }
                            else
                            {
                                menu.AddDisabledItem(EditorGUIUtility.TextContent("HierarchyPopupRename"));
                            }
                            menu.AddSeparator(string.Empty);
                            menu.AddItem(EditorGUIUtility.TextContent("HierarchyPopupDelete"), false, new GenericMenu.MenuFunction(this.DeleteGO));
                            base.Focus();
                            menu.DropDown(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f));
                            current.Use();
                        }
                    }
                    else if ((current.type == EventType.DragUpdated) || (current.type == EventType.DragPerform))
                    {
                        Rect rect6 = rect3;
                        rect6.yMin -= m_DropNextToAreaHeight * 2f;
                        if (rect6.Contains(mousePosition))
                        {
                            if ((mousePosition.y - rect3.y) < m_DropNextToAreaHeight)
                            {
                                this.DragElement(newHierarchyProperty, false);
                            }
                            else
                            {
                                this.DragElement(newHierarchyProperty, true);
                            }
                            GUIUtility.hotControl = 0;
                        }
                    }
                    top += m_RowHeight;
                }
                if (flag3)
                {
                    GUIStyle insertion = ms_Styles.insertion;
                    if (current.type == EventType.Repaint)
                    {
                        insertion.Draw(position, false, false, false, false);
                    }
                }
                if ((this.m_EditNameMode == NameEditMode.PreImportNaming) && (this.m_NewAssetSortInstanceID == 0))
                {
                    this.DrawPreImportedIcon(top + 16f);
                }
                this.HandlePing();
                GUI.EndScrollView();
                switch (current.type)
                {
                    case EventType.DragUpdated:
                        if (!(base.m_SearchFilter == string.Empty))
                        {
                            if (this.m_DropData == null)
                            {
                                this.m_DropData = new DropData();
                            }
                            this.m_DropData.dropOnControlID = 0;
                            this.m_DropData.dropPreviousControlID = 0;
                            return;
                        }
                        this.DragElement(null, true);
                        return;

                    case EventType.DragPerform:
                        this.m_CurrentDragSelectionIDs.Clear();
                        this.DragElement(null, true);
                        return;

                    case EventType.DragExited:
                        this.m_CurrentDragSelectionIDs.Clear();
                        this.DragCleanup(true);
                        return;

                    case EventType.ContextClick:
                        if ((base.m_HierarchyType == HierarchyType.Assets) && this.m_ScreenRect.Contains(current.mousePosition))
                        {
                            EditorUtility.DisplayPopupMenu(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f), "Assets/", null);
                            current.Use();
                        }
                        return;

                    case EventType.MouseDown:
                        if ((current.button == 0) && this.m_ScreenRect.Contains(current.mousePosition))
                        {
                            GUIUtility.hotControl = num6;
                            Selection.activeObject = null;
                            this.EndNameEditing();
                            current.Use();
                        }
                        break;

                    case EventType.MouseUp:
                        if (GUIUtility.hotControl == num6)
                        {
                            GUIUtility.hotControl = 0;
                            current.Use();
                        }
                        break;

                    case EventType.KeyDown:
                        if ((this.m_EditNameMode == NameEditMode.Found) && ((((current.keyCode == KeyCode.Return) || (current.keyCode == KeyCode.KeypadEnter)) && (Application.platform == RuntimePlatform.OSXEditor)) || ((current.keyCode == KeyCode.F2) && (Application.platform == RuntimePlatform.WindowsEditor))))
                        {
                            this.BeginNameEditing(Selection.activeInstanceID);
                            current.Use();
                        }
                        break;
                }
            }
        }

        private void KeyboardGUI()
        {
            int controlID = GUIUtility.GetControlID(FocusType.Keyboard);
            if (Event.current.GetTypeForControl(controlID) == EventType.KeyDown)
            {
                switch (Event.current.keyCode)
                {
                    case KeyCode.KeypadEnter:
                    case KeyCode.Return:
                        if (Application.platform == RuntimePlatform.WindowsEditor)
                        {
                            this.OpenAssetSelection();
                            GUIUtility.ExitGUI();
                        }
                        return;

                    case KeyCode.UpArrow:
                        Event.current.Use();
                        this.SelectPrevious();
                        return;

                    case KeyCode.DownArrow:
                        Event.current.Use();
                        if ((Application.platform != RuntimePlatform.OSXEditor) || !Event.current.command)
                        {
                            this.SelectNext();
                            return;
                        }
                        this.OpenAssetSelection();
                        GUIUtility.ExitGUI();
                        return;

                    case KeyCode.RightArrow:
                    {
                        int[] instanceIDs = Selection.instanceIDs;
                        for (int i = 0; i < instanceIDs.Length; i++)
                        {
                            this.SetExpanded(instanceIDs[i], true);
                        }
                        Event.current.Use();
                        return;
                    }
                    case KeyCode.LeftArrow:
                    {
                        int[] numArray = Selection.instanceIDs;
                        for (int j = 0; j < numArray.Length; j++)
                        {
                            this.SetExpanded(numArray[j], false);
                        }
                        Event.current.Use();
                        return;
                    }
                    case KeyCode.Home:
                        if (this.GetFirst() != null)
                        {
                            Selection.activeObject = this.GetFirst().pptrValue;
                            this.FrameObject(Selection.activeInstanceID);
                        }
                        return;

                    case KeyCode.End:
                        if (this.GetLast() != null)
                        {
                            Selection.activeObject = this.GetLast().pptrValue;
                            this.FrameObject(Selection.activeInstanceID);
                        }
                        return;

                    case KeyCode.PageUp:
                        Event.current.Use();
                        if (Application.platform != RuntimePlatform.OSXEditor)
                        {
                            IHierarchyProperty firstSelected = this.GetFirstSelected();
                            if (firstSelected == null)
                            {
                                if (this.GetFirst() != null)
                                {
                                    Selection.activeObject = this.GetFirst().pptrValue;
                                    this.FrameObject(Selection.activeInstanceID);
                                }
                                return;
                            }
                            for (int k = 0; k < (this.m_ScreenRect.height / m_RowHeight); k++)
                            {
                                if (!firstSelected.Previous(this.m_ExpandedArray))
                                {
                                    firstSelected = this.GetFirst();
                                    break;
                                }
                            }
                            int instanceID = firstSelected.instanceID;
                            this.SelectionClick(firstSelected);
                            this.FrameObject(instanceID);
                            return;
                        }
                        this.m_ScrollPosition.y -= this.m_ScreenRect.height;
                        if (this.m_ScrollPosition.y < 0f)
                        {
                            this.m_ScrollPosition.y = 0f;
                        }
                        return;

                    case KeyCode.PageDown:
                        Event.current.Use();
                        if (Application.platform != RuntimePlatform.OSXEditor)
                        {
                            IHierarchyProperty lastSelected = this.GetLastSelected();
                            if (lastSelected == null)
                            {
                                if (this.GetLast() != null)
                                {
                                    Selection.activeObject = this.GetLast().pptrValue;
                                    this.FrameObject(Selection.activeInstanceID);
                                }
                                return;
                            }
                            for (int m = 0; m < (this.m_ScreenRect.height / m_RowHeight); m++)
                            {
                                if (!lastSelected.Next(this.m_ExpandedArray))
                                {
                                    lastSelected = this.GetLast();
                                    break;
                                }
                            }
                            int targetInstanceID = lastSelected.instanceID;
                            this.SelectionClick(lastSelected);
                            this.FrameObject(targetInstanceID);
                            return;
                        }
                        this.m_ScrollPosition.y += this.m_ScreenRect.height;
                        return;
                }
            }
        }

        private bool NamingAsset()
        {
            return ((this.m_EditNameMode == NameEditMode.Renaming) || (this.m_EditNameMode == NameEditMode.PreImportNaming));
        }

        public override void OnDisable()
        {
            base.OnDisable();
            EditorApplication.playmodeStateChanged = (EditorApplication.CallbackFunction) Delegate.Remove(EditorApplication.playmodeStateChanged, new EditorApplication.CallbackFunction(this.OnPlayModeStateChanged));
        }

        public override void OnEnable()
        {
            base.OnEnable();
            EditorApplication.playmodeStateChanged = (EditorApplication.CallbackFunction) Delegate.Combine(EditorApplication.playmodeStateChanged, new EditorApplication.CallbackFunction(this.OnPlayModeStateChanged));
        }

        private void OnFocus()
        {
            this.m_FocusTime = Time.realtimeSinceStartup;
        }

        private void OnGUI()
        {
            if (ms_Styles == null)
            {
                ms_Styles = new Styles();
            }
            EditorGUIUtility.LookLikeControls();
            this.ProjectWindowTitle();
            Rect rect = GUILayoutUtility.GetRect(0f, (float) Screen.width, 0f, (float) Screen.height);
            if ((base.m_HierarchyType == HierarchyType.Assets) && AssetDatabase.isLocked)
            {
                Debug.LogError("Repainting while performing asset operations!");
                GUILayout.Label("Performing Asset operations", new GUILayoutOption[0]);
            }
            else
            {
                this.m_ScreenRect = rect;
                EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
                this.HierarchyView();
                this.SearchResultPathGUI();
                EditorGUIUtility.SetIconSize(Vector2.zero);
                if ((Event.current.type == EventType.Repaint) && this.m_NeedsRelayout)
                {
                    this.m_NeedsRelayout = false;
                    if (this.m_FrameAfterRelayout != 0)
                    {
                        this.FrameObject(this.m_FrameAfterRelayout);
                        this.m_FrameAfterRelayout = 0;
                    }
                }
            }
        }

        private void OnHierarchyChange()
        {
            if (base.m_HierarchyType == HierarchyType.GameObjects)
            {
                this.EndNameEditing();
                if (this.m_FilteredHierarchy != null)
                {
                    this.m_FilteredHierarchy.ResultsChanged();
                }
                base.Repaint();
            }
        }

        private void OnLostFocus()
        {
            this.m_StillWantsNameEditing = false;
            this.EndNameEditing();
        }

        private void OnPlayModeStateChanged()
        {
            this.EndNameEditing();
        }

        private void OnProjectChange()
        {
            if (base.m_HierarchyType == HierarchyType.Assets)
            {
                this.CancelNameEditing();
                if (this.m_FilteredHierarchy != null)
                {
                    this.m_FilteredHierarchy.ResultsChanged();
                }
                base.Repaint();
            }
        }

        private void OnSelectionChange()
        {
            if (Selection.activeInstanceID != this.m_EditNameInstanceID)
            {
                this.EndNameEditing();
            }
            this.m_StillWantsNameEditing = false;
            this.RevealObjects(Selection.instanceIDs);
            if (this.m_ProjectViewInternalSelectionChange)
            {
                this.m_ProjectViewInternalSelectionChange = false;
            }
            else if (base.m_HierarchyType == HierarchyType.GameObjects)
            {
                this.FrameObject(Selection.activeInstanceID);
            }
            base.Repaint();
        }

        private void OpenAssetSelection()
        {
            foreach (int num in Selection.instanceIDs)
            {
                if (AssetDatabase.Contains(num))
                {
                    AssetDatabase.OpenAsset(num);
                }
            }
        }

        private void PasteGO()
        {
            Unsupported.PasteGameObjectsFromPasteboard();
        }

        internal void PingTargetObject(int targetInstanceID)
        {
            if (targetInstanceID != 0)
            {
                if (ms_Styles == null)
                {
                    ms_Styles = new Styles();
                }
                if (this.FrameObject(targetInstanceID))
                {
                    IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
                    int num = 0;
                    num = newHierarchyProperty.CountRemaining(this.m_ExpandedArray);
                    IHierarchyProperty property2 = this.GetNewHierarchyProperty();
                    if (property2.Find(targetInstanceID, this.m_ExpandedArray))
                    {
                        int row = property2.row;
                        float num3 = m_RowHeight * row;
                        this.m_Ping.m_ContentTopLeft = new Vector2((float) ((int) (17f + (16f * property2.depth))), num3 + 2f);
                        this.m_Ping.m_Content = new GUIContent(property2.name, property2.icon);
                        this.m_Ping.m_TimeStart = Time.realtimeSinceStartup;
                        this.m_Ping.m_PingStyle = ms_Styles.ping;
                        float num4 = ((num * m_RowHeight) <= this.m_ScreenRect.height) ? 0f : -16f;
                        this.m_Ping.m_AvailableWidth = base.position.width + num4;
                        base.Repaint();
                        return;
                    }
                }
                targetInstanceID = InternalEditorUtility.GetGameObjectInstanceIDFromComponent(targetInstanceID);
                if (targetInstanceID != 0)
                {
                    this.PingTargetObject(targetInstanceID);
                }
            }
        }

        private void ProjectWindowTitle()
        {
            GUILayout.BeginHorizontal("Toolbar", new GUILayoutOption[0]);
            if (base.m_HierarchyType == HierarchyType.Assets)
            {
                this.CreateAssetPopup();
                GUILayout.Space(6f);
            }
            else
            {
                this.CreateGameObjectPopup();
                GUILayout.Space(6f);
            }
            if (this.m_FilteredHierarchy == null)
            {
                this.GetNewHierarchyProperty();
            }
            int controlID = GUIUtility.GetControlID(FocusType.Keyboard);
            if (Event.current.GetTypeForControl(controlID) == EventType.KeyDown)
            {
                switch (Event.current.keyCode)
                {
                    case KeyCode.KeypadEnter:
                    case KeyCode.UpArrow:
                    case KeyCode.DownArrow:
                    case KeyCode.Return:
                        EditorGUILayout.EndHorizontal();
                        return;

                    case KeyCode.RightArrow:
                    case KeyCode.LeftArrow:
                        if (base.hasSearchFilter)
                        {
                            break;
                        }
                        EditorGUILayout.EndHorizontal();
                        return;
                }
            }
            GUILayout.FlexibleSpace();
            base.SearchFieldGUI();
            GUILayout.EndHorizontal();
        }

        private void RenameGO(object obj)
        {
            GameObject obj2 = (GameObject) obj;
            Selection.activeObject = obj2;
            this.BeginNameEditing(Selection.activeInstanceID);
            base.Repaint();
        }

        private bool RevealObject(int targetInstanceID)
        {
            return this.RevealObject(targetInstanceID, true);
        }

        private bool RevealObject(int targetInstanceID, bool allowClearSearchFilter)
        {
            IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
            if (newHierarchyProperty.Find(targetInstanceID, null))
            {
                while (newHierarchyProperty.Parent())
                {
                    this.SetExpanded(newHierarchyProperty.instanceID, true);
                }
                return true;
            }
            if (allowClearSearchFilter)
            {
                newHierarchyProperty = new HierarchyProperty(base.m_HierarchyType);
                if (newHierarchyProperty.Find(targetInstanceID, null))
                {
                    base.ClearSearchFilter();
                    return this.RevealObject(targetInstanceID, true);
                }
            }
            return false;
        }

        private void RevealObjects(int[] targetInstanceIDs)
        {
            int[] numArray = this.GetNewHierarchyProperty().FindAllAncestors(targetInstanceIDs);
            for (int i = 0; i < numArray.Length; i++)
            {
                this.SetExpanded(numArray[i], true);
            }
        }

        private void SearchResultPathGUI()
        {
            if (base.hasSearchFilter)
            {
                EditorGUILayout.BeginVertical(EditorStyles.inspectorBig, new GUILayoutOption[0]);
                GUILayout.Label("Path:", new GUILayoutOption[0]);
                IHierarchyProperty activeSelected = this.GetActiveSelected();
                if (activeSelected != null)
                {
                    IHierarchyProperty property2 = new HierarchyProperty(base.m_HierarchyType);
                    property2.Find(activeSelected.instanceID, null);
                    do
                    {
                        EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        GUILayout.Label(property2.icon, new GUILayoutOption[0]);
                        GUILayout.Label(property2.name, new GUILayoutOption[0]);
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.EndHorizontal();
                    }
                    while (property2.Parent());
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(0f);
            }
        }

        private void SelectAll()
        {
            IHierarchyProperty newHierarchyProperty = this.GetNewHierarchyProperty();
            List<int> list = new List<int>();
            while (newHierarchyProperty.Next(this.m_ExpandedArray))
            {
                list.Add(newHierarchyProperty.instanceID);
            }
            Selection.instanceIDs = list.ToArray();
        }

        private void SelectionClick(IHierarchyProperty property)
        {
            List<int> selection = this.GetSelection(property, false);
            if (selection.Count == 1)
            {
                Selection.activeInstanceID = selection[0];
            }
            else
            {
                Selection.instanceIDs = selection.ToArray();
            }
            this.m_ProjectViewInternalSelectionChange = true;
            if (base.hasSearchFilter)
            {
                this.m_DidSelectSearchResult = true;
                this.m_NeedsRelayout = true;
            }
        }

        private void SelectionClickContextMenu(IHierarchyProperty property)
        {
            if (!Selection.Contains(property.instanceID))
            {
                Selection.activeInstanceID = property.instanceID;
            }
        }

        public void SelectNext()
        {
            IHierarchyProperty lastSelected = this.GetLastSelected();
            if (lastSelected != null)
            {
                if (lastSelected.Next(this.m_ExpandedArray))
                {
                    this.SelectionClick(lastSelected);
                    this.FrameObject(lastSelected.instanceID);
                }
            }
            else if (this.GetFirst() != null)
            {
                Selection.activeInstanceID = this.GetFirst().instanceID;
                this.FrameObject(Selection.activeInstanceID);
            }
        }

        public void SelectPrevious()
        {
            IHierarchyProperty firstSelected = this.GetFirstSelected();
            if (firstSelected != null)
            {
                if (firstSelected.Previous(this.m_ExpandedArray))
                {
                    this.FrameObject(firstSelected.instanceID);
                    this.SelectionClick(firstSelected);
                }
            }
            else if (this.GetLast() != null)
            {
                Selection.activeInstanceID = this.GetLast().instanceID;
                this.FrameObject(Selection.activeInstanceID);
            }
        }

        private void SetExpanded(int instanceID, bool expand)
        {
            Hashtable hashtable = new Hashtable();
            for (int i = 0; i < this.m_ExpandedArray.Length; i++)
            {
                hashtable.Add(this.m_ExpandedArray[i], null);
            }
            if (expand != hashtable.Contains(instanceID))
            {
                if (expand)
                {
                    hashtable.Add(instanceID, null);
                }
                else
                {
                    hashtable.Remove(instanceID);
                }
                this.m_ExpandedArray = new int[hashtable.Count];
                int index = 0;
                IEnumerator enumerator = hashtable.Keys.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        this.m_ExpandedArray[index] = (int) enumerator.Current;
                        index++;
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable == null)
                    {
                    }
                    disposable.Dispose();
                }
            }
            if (base.m_HierarchyType == HierarchyType.Assets)
            {
                InternalEditorUtility.expandedProjectWindowItems = this.m_ExpandedArray;
            }
        }

        public void SetExpandedRecurse(int instanceID, bool expand)
        {
            IHierarchyProperty property = new HierarchyProperty(base.m_HierarchyType);
            if (property.Find(instanceID, this.m_ExpandedArray))
            {
                this.SetExpanded(instanceID, expand);
                int depth = property.depth;
                while (property.Next(null) && (property.depth > depth))
                {
                    this.SetExpanded(property.instanceID, expand);
                }
            }
        }

        internal override void SetSearchFilter(string searchFilter, SearchableEditorWindow.SearchMode searchMode, bool setAll)
        {
            int targetInstanceID = 0;
            if (this.m_DidSelectSearchResult && (this.GetFirstSelected() != null))
            {
                targetInstanceID = this.GetFirstSelected().instanceID;
            }
            base.SetSearchFilter(searchFilter, searchMode, setAll);
            if (this.m_FilteredHierarchy == null)
            {
                this.GetNewHierarchyProperty();
            }
            this.m_FilteredHierarchy.searchFilter = SearchableEditorWindow.CreateFilter(searchFilter, searchMode);
            if (this.m_DidSelectSearchResult)
            {
                if (searchFilter == string.Empty)
                {
                    this.m_DidSelectSearchResult = false;
                    this.m_NeedsRelayout = true;
                }
                if (targetInstanceID != 0)
                {
                    this.FrameObject(targetInstanceID, false);
                }
            }
        }

        public void Show()
        {
            this.Awake();
            base.Show();
        }

        private void StartDrag(IHierarchyProperty property)
        {
            DragAndDrop.PrepareStartDrag();
            DragAndDrop.objectReferences = this.GetDragAndDropObjects(property.pptrValue);
            DragAndDrop.paths = this.GetDragAndDropPaths(property.instanceID);
            if (DragAndDrop.objectReferences.Length > 1)
            {
                DragAndDrop.StartDrag("<Multiple>");
            }
            else
            {
                DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(property.pptrValue));
            }
        }

        private float IconWidth
        {
            get
            {
                return ((base.m_HierarchyType != HierarchyType.Assets) ? ((float) (-3)) : ((float) 14));
            }
        }

        private NameEditMode m_EditNameMode
        {
            get
            {
                return this.m_RealEditNameMode;
            }
            set
            {
                if (value != this.m_RealEditNameMode)
                {
                    this.m_RealEditNameMode = value;
                }
            }
        }

        private class DropData
        {
            public int dropOnControlID;
            public int dropPreviousControlID;
            public int[] expandedArrayBeforeDrag;
            public double expandItemBeginTimer;
            public int lastControlID;
        }

        private enum NameEditMode
        {
            None,
            Found,
            Renaming,
            PreImportNaming
        }

        internal class Styles
        {
            public GUIStyle foldout = "IN Foldout";
            public GUIStyle hiLabel = "HI Label";
            public GUIStyle insertion = "PR Insertion";
            public GUIStyle label = "PR Label";
            public GUIStyle ping = "PR Ping";
        }
    }
}

